package lab10;

import java.security.InvalidParameterException;

public class Car {
	private String model;
	private String color;
	private int maxSpeed;
	private int price;
	private boolean isSportsCar;
	private Person owner;

	public void setModel(String model) {
		if (model != null && model.trim().length() > 0)
			this.model = model;
		else
			throw new InvalidParameterException("Model name is empty.");
	}

	public String getModel() {
		return model;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		if (color != null && color.trim().length() > 0)
			this.color = color;
		else
			throw new InvalidParameterException("Color is empty.");
	}

	public int getMaxSpeed() {
		return maxSpeed;
	}

	public void setMasXpeed(int maxSpeed) {
		if ((!isSportsCar) && (maxSpeed > 200))
			this.maxSpeed = 200;
		else if (maxSpeed < 0)
			this.maxSpeed = 0;
		else
			this.maxSpeed = maxSpeed;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		if (price > 0)
			this.price = price;
		else
			throw new InvalidParameterException("Price is negative.");
	}

	public void setIsSportsCar(boolean isSportsCar) {
		this.isSportsCar = isSportsCar;
	}

	public boolean getIsSportsCar() {
		return isSportsCar;
	}

	public void setOwner(Person owner) {
		this.owner = owner;
	}

	public Person getOwner() {
		return owner;
	}

	public Car(String model, String color, boolean isSportsCar) {
		this(model, color, 0, 0, isSportsCar);
	}

	public Car(String model, String color, int maxSpeed, int price,
			boolean isSportsCar) {
		super();
		this.model = model;
		this.color = color;
		this.isSportsCar = isSportsCar;
		if ((!isSportsCar) && (maxSpeed > 200))
			this.maxSpeed = 200;
		else
			this.maxSpeed = maxSpeed;
		this.price = price;
	}

	boolean isMoreExpensive(Car car) {
		if (car != null)
			return (this.price > car.price);
		else
			throw new InvalidParameterException("Can't compare price with null");
	}

	double calculateCarPriceForScrap() {
		double coef = 0.2;
		if (isSportsCar)
			coef += 0.05;
		if (color == "white" || color == "black")
			coef += 0.05;
		return price * coef;
	}
}
